package com.cheung.leetcode.day;

import  org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.day
 * @Author :  cheungming
 * @CreateTime : 2024-07-07 07:52:27
 * @Description : 每日 一题
 * @Version : 1.0
 */
public class Code88Test {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        // 1. 暴力解法
        if (n >= 0) System.arraycopy(nums2, 0, nums1, m, n);
        Arrays.sort(nums1);
    }


    @Test
    public void test1() {
        int[] nums1 = new int[]{1, 2, 3, 0, 0, 0};
        int[] nums2 = new int[]{2, 5, 6};
        merge(nums1, 3, nums2, 3);
        int[] res = new int[]{1, 2, 2, 3, 5, 6};
        assert Arrays.equals(nums1, res);
    }

    @Test
    public void test2() {
        int[] nums1 = new int[]{1};
        int[] nums2 = new int[]{};
        merge(nums1, 1, nums2, 0);
        int[] res = new int[]{1};
        assert Arrays.equals(nums1, res);
    }

    @Test
    public void test3() {
        int[] nums1 = new int[]{0};
        int[] nums2 = new int[]{1};
        merge(nums1, 0, nums2, 1);
        int[] res = new int[]{1};
        assert Arrays.equals(nums1, res);
    }

    @Test
    public void test4() {
        int[] nums1 = new int[]{2, 0};
        int[] nums2 = new int[]{1};
        merge(nums1, 1, nums2, 1);
        int[] res = new int[]{1, 2};
        assert Arrays.equals(nums1, res);
    }


}
